<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@include file="/common/common.jsp" %>
    <link rel="stylesheet" href="${basePath}/css/layerPage.css${VERSION}"/>
</head>
<body>
<form id="form" name="form" class="form-horizontal" method="post" action="${basePath}/mobileRole/toAdd">
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-3 control-label">角色名：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="roleName" name="roleName"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">角色描述：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="roleDesc" name="roleDesc"/>
            </div>
        </div>
        <button id="submit" type="submit" class="btn btn-primary btn-submit">提交</button>
    </div>
</form>
<script type="text/javascript">
    jQuery(function ($) {
        var $form = $("#form");
        var $submit = $("#submit");

        $form.validate({
            errorClass: 'error-msg',
            rules: {
                roleName: {
                    required: true,
                    maxlength: 50
                },
                roleDesc: {
                    maxlength: 255
                }
            },
            messages: {
                roleName: {
                    required: "角色名称",
                    maxlength: "角色名称过长"
                },
                roleDesc: {
                    maxlength: "角色描述过长"
                }
            },
            submitHandler: function (form) {
                $.ajax({
                    url: $form.attr("action"),
                    type: $form.attr("method"),
                    data: $form.serialize(),
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $submit.prop("disabled", true);
                    },
                    success: function (data) {
                        if (data.status == '0') {
                            $submit.prop("disabled", false);
                            layer.confirm('添加成功！是否关闭窗口？', {icon: 1}, function (index) {
                                parent.$("#grid-table").jqGrid().trigger("reloadGrid", [{page: 1}]);
                                parent.layer.close(parent.pageii);
                                return false
                            });
                        } else {
                            $submit.prop("disabled", false);
                            layer.alert(data.message, {
                                icon: 0,
                                skin: 'layui-layer-lan',
                                closeBtn: 0
                            });
                        }
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        $submit.prop("disabled", false);
                        layer.alert("系统未知错误", {
                            icon: 0,
                            skin: 'layui-layer-lan',
                            closeBtn: 0
                        });
                    }
                });
            }
        });
    });
</script>
</body>
</html>
